//
//  HZGoodsCommentModel.m
//  app
//
//  Created by 刘华舟 on 15/5/26.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsCommentModel.h"
#import "NSDictionary+SafetyGet.h"

@implementation HZGoodsCommentModel

+ (instancetype)modelWithDictionary:(NSDictionary *)dict{
    return [[HZGoodsCommentModel alloc] initModelWithDictionary:dict];
}

- (instancetype)initModelWithDictionary:(NSDictionary *)dict{
    if (self = [super init]) {
        _commentID = [dict stringForKey:APIKEY_mall_id nilValue:@"0"];
        _userID = [dict stringForKey:APIKEY_mall_uid nilValue:@"0"];
        _faceURL = [dict stringForKey:APIKEY_mall_face nilValue:@""];
        _nickname = [dict stringForKey:APIKEY_mall_nickname nilValue:@""];
        _contents = [dict stringForKey:APIKEY_mall_contents nilValue:@""];
        _replys = [[dict arrayForKey:APIKEY_mall_subReply] firstObject];
        _pics = [dict arrayForKey:APIKEY_mall_pics];
        _scores = [dict stringForKey:APIKEY_mall_scores nilValue:@"0"];
        _dateline = [dict stringForKey:APIKEY_mall_dateline nilValue:@""];
        
        _cellHeight = [UBO_SCREEN uh:kHZGoodsCommentCellHeight];
        
        
        if (_contents.length) {
            CGSize contentTextSize = [self.contents boundingRectWithSize:[UBO_SCREEN fw:UB_WIDTH uw:-(kSizeMallViewMargin*2) uh:kContentTextMaxHeight] options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:JKAppGlobleFontSmallTagText} context:nil].size;
            
            
            _cellHeight += (contentTextSize.height + [UBO_SCREEN uh:kSizeMallViewMargin]);
        }

        if (self.pics.count) {
            _cellHeight += ([UBO_SCREEN uh:kSizeMallViewMargin+kHZGoodsCommentPictureHeight]);
        }
        
        if (_replys.count) {
            NSString *replys = [_replys stringForKey:APIKEY_mall_contents nilValue:@""];
            CGSize contentTextSize = [[NSString stringWithFormat:@"客服回复：%@", replys] boundingRectWithSize:[UBO_SCREEN fw:UB_WIDTH uw:-(kSizeMallViewMargin*4) uh:kContentTextMaxHeight] options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:JKAppGlobleFontSmallTagText} context:nil].size;
            
            
            _cellHeight += (contentTextSize.height + [UBO_SCREEN uh:3*kSizeMallViewMargin]);
        }
        
        
    }
    return self;
}

@end
